Imports cmplib01

Public Class frmDeployment2
    Inherits System.Windows.Forms.Form

    Private bPointValueInvalid As Boolean = False
    Private bUsingOOB As Boolean
    Private bCancelled As Boolean = True
    Private unit As New BattlegroupChit
    Private ptrcurrentGame As CampaignerGameData
    Private ptrDepZone As DeploymentZone

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents txtAvailablePoints As System.Windows.Forms.TextBox
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents lblFactionPV As System.Windows.Forms.Label
    Friend WithEvents lblDeploy As System.Windows.Forms.Label
    Friend WithEvents txtDeploymentzonename As System.Windows.Forms.TextBox
    Friend WithEvents lblDeploymentPV As System.Windows.Forms.Label
    Friend WithEvents txtDeploymentPV As System.Windows.Forms.TextBox
    Friend WithEvents lblPVThisTurn As System.Windows.Forms.Label
    Friend WithEvents txtPVThisTurn As System.Windows.Forms.TextBox
    Friend WithEvents cruCreateUnit As CTest.ctlCreateUnit
    Friend WithEvents cbgBattlegroup As CTest.ctlCreateBattleGroups
    Friend WithEvents btnCreateBG As System.Windows.Forms.Button
    Friend WithEvents btnCreateUnit As System.Windows.Forms.Button
    Friend WithEvents btnUseOOB As System.Windows.Forms.Button
    Friend WithEvents oobSelectUnit As CTest.ctlSelectOOBUnit
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmDeployment2))
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnOK = New System.Windows.Forms.Button
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.lblFactionPV = New System.Windows.Forms.Label
        Me.txtAvailablePoints = New System.Windows.Forms.TextBox
        Me.lblDeploy = New System.Windows.Forms.Label
        Me.txtDeploymentzonename = New System.Windows.Forms.TextBox
        Me.lblDeploymentPV = New System.Windows.Forms.Label
        Me.txtDeploymentPV = New System.Windows.Forms.TextBox
        Me.lblPVThisTurn = New System.Windows.Forms.Label
        Me.txtPVThisTurn = New System.Windows.Forms.TextBox
        Me.btnCreateUnit = New System.Windows.Forms.Button
        Me.btnCreateBG = New System.Windows.Forms.Button
        Me.btnUseOOB = New System.Windows.Forms.Button
        Me.cruCreateUnit = New CTest.ctlCreateUnit
        Me.cbgBattlegroup = New CTest.ctlCreateBattleGroups
        Me.oobSelectUnit = New CTest.ctlSelectOOBUnit
        Me.SuspendLayout()
        '
        'btnCancel
        '
        Me.btnCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnCancel.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.Location = New System.Drawing.Point(488, 504)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.TabIndex = 24
        Me.btnCancel.Text = "Cancel"
        '
        'btnOK
        '
        Me.btnOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(408, 504)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 23
        Me.btnOK.Text = "OK"
        '
        'ImageList1
        '
        Me.ImageList1.ImageSize = New System.Drawing.Size(32, 32)
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'lblFactionPV
        '
        Me.lblFactionPV.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblFactionPV.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblFactionPV.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.lblFactionPV.Location = New System.Drawing.Point(8, 440)
        Me.lblFactionPV.Name = "lblFactionPV"
        Me.lblFactionPV.Size = New System.Drawing.Size(160, 16)
        Me.lblFactionPV.TabIndex = 8
        Me.lblFactionPV.Text = "Faction Point Value (PV)"
        '
        'txtAvailablePoints
        '
        Me.txtAvailablePoints.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtAvailablePoints.BackColor = System.Drawing.Color.WhiteSmoke
        Me.txtAvailablePoints.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtAvailablePoints.Location = New System.Drawing.Point(176, 440)
        Me.txtAvailablePoints.Name = "txtAvailablePoints"
        Me.txtAvailablePoints.ReadOnly = True
        Me.txtAvailablePoints.Size = New System.Drawing.Size(112, 20)
        Me.txtAvailablePoints.TabIndex = 7
        Me.txtAvailablePoints.Text = "0"
        Me.txtAvailablePoints.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblDeploy
        '
        Me.lblDeploy.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblDeploy.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblDeploy.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.lblDeploy.Location = New System.Drawing.Point(8, 472)
        Me.lblDeploy.Name = "lblDeploy"
        Me.lblDeploy.Size = New System.Drawing.Size(160, 16)
        Me.lblDeploy.TabIndex = 26
        Me.lblDeploy.Text = "Deployment Zone"
        '
        'txtDeploymentzonename
        '
        Me.txtDeploymentzonename.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtDeploymentzonename.BackColor = System.Drawing.Color.WhiteSmoke
        Me.txtDeploymentzonename.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtDeploymentzonename.Location = New System.Drawing.Point(176, 472)
        Me.txtDeploymentzonename.Name = "txtDeploymentzonename"
        Me.txtDeploymentzonename.ReadOnly = True
        Me.txtDeploymentzonename.Size = New System.Drawing.Size(112, 20)
        Me.txtDeploymentzonename.TabIndex = 25
        Me.txtDeploymentzonename.Text = "DepZone"
        Me.txtDeploymentzonename.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblDeploymentPV
        '
        Me.lblDeploymentPV.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblDeploymentPV.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblDeploymentPV.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.lblDeploymentPV.Location = New System.Drawing.Point(296, 440)
        Me.lblDeploymentPV.Name = "lblDeploymentPV"
        Me.lblDeploymentPV.Size = New System.Drawing.Size(160, 16)
        Me.lblDeploymentPV.TabIndex = 28
        Me.lblDeploymentPV.Text = "Deployment PV"
        '
        'txtDeploymentPV
        '
        Me.txtDeploymentPV.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtDeploymentPV.BackColor = System.Drawing.Color.WhiteSmoke
        Me.txtDeploymentPV.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtDeploymentPV.Location = New System.Drawing.Point(456, 438)
        Me.txtDeploymentPV.Name = "txtDeploymentPV"
        Me.txtDeploymentPV.ReadOnly = True
        Me.txtDeploymentPV.Size = New System.Drawing.Size(112, 20)
        Me.txtDeploymentPV.TabIndex = 27
        Me.txtDeploymentPV.Text = "0"
        Me.txtDeploymentPV.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'lblPVThisTurn
        '
        Me.lblPVThisTurn.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblPVThisTurn.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblPVThisTurn.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.lblPVThisTurn.Location = New System.Drawing.Point(296, 472)
        Me.lblPVThisTurn.Name = "lblPVThisTurn"
        Me.lblPVThisTurn.Size = New System.Drawing.Size(160, 16)
        Me.lblPVThisTurn.TabIndex = 30
        Me.lblPVThisTurn.Text = "PV This Turn"
        '
        'txtPVThisTurn
        '
        Me.txtPVThisTurn.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.txtPVThisTurn.BackColor = System.Drawing.Color.WhiteSmoke
        Me.txtPVThisTurn.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPVThisTurn.Location = New System.Drawing.Point(456, 470)
        Me.txtPVThisTurn.Name = "txtPVThisTurn"
        Me.txtPVThisTurn.ReadOnly = True
        Me.txtPVThisTurn.Size = New System.Drawing.Size(112, 20)
        Me.txtPVThisTurn.TabIndex = 29
        Me.txtPVThisTurn.Text = "0"
        Me.txtPVThisTurn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'btnCreateUnit
        '
        Me.btnCreateUnit.BackColor = System.Drawing.Color.DeepSkyBlue
        Me.btnCreateUnit.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCreateUnit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCreateUnit.Location = New System.Drawing.Point(16, 10)
        Me.btnCreateUnit.Name = "btnCreateUnit"
        Me.btnCreateUnit.TabIndex = 31
        Me.btnCreateUnit.Text = "Create Unit"
        '
        'btnCreateBG
        '
        Me.btnCreateBG.BackColor = System.Drawing.Color.LightBlue
        Me.btnCreateBG.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCreateBG.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnCreateBG.Location = New System.Drawing.Point(96, 10)
        Me.btnCreateBG.Name = "btnCreateBG"
        Me.btnCreateBG.TabIndex = 32
        Me.btnCreateBG.Text = "Create BG"
        '
        'btnUseOOB
        '
        Me.btnUseOOB.BackColor = System.Drawing.Color.LightBlue
        Me.btnUseOOB.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnUseOOB.ForeColor = System.Drawing.SystemColors.ControlText
        Me.btnUseOOB.Location = New System.Drawing.Point(176, 10)
        Me.btnUseOOB.Name = "btnUseOOB"
        Me.btnUseOOB.TabIndex = 33
        Me.btnUseOOB.Text = "Use OOB"
        '
        'cruCreateUnit
        '
        Me.cruCreateUnit.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cruCreateUnit.Location = New System.Drawing.Point(8, 32)
        Me.cruCreateUnit.Name = "cruCreateUnit"
        Me.cruCreateUnit.Size = New System.Drawing.Size(568, 400)
        Me.cruCreateUnit.TabIndex = 34
        Me.cruCreateUnit.Unit = Nothing
        '
        'cbgBattlegroup
        '
        Me.cbgBattlegroup.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.cbgBattlegroup.Location = New System.Drawing.Point(8, 32)
        Me.cbgBattlegroup.Name = "cbgBattlegroup"
        Me.cbgBattlegroup.Size = New System.Drawing.Size(568, 400)
        Me.cbgBattlegroup.TabIndex = 35
        Me.cbgBattlegroup.Unit = Nothing
        Me.cbgBattlegroup.Visible = False
        '
        'oobSelectUnit
        '
        Me.oobSelectUnit.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.oobSelectUnit.Location = New System.Drawing.Point(8, 32)
        Me.oobSelectUnit.Name = "oobSelectUnit"
        Me.oobSelectUnit.Size = New System.Drawing.Size(568, 400)
        Me.oobSelectUnit.TabIndex = 36
        Me.oobSelectUnit.Unit = Nothing
        Me.oobSelectUnit.Visible = False
        '
        'frmDeployment2
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(584, 534)
        Me.Controls.Add(Me.cbgBattlegroup)
        Me.Controls.Add(Me.cruCreateUnit)
        Me.Controls.Add(Me.btnUseOOB)
        Me.Controls.Add(Me.btnCreateBG)
        Me.Controls.Add(Me.btnCreateUnit)
        Me.Controls.Add(Me.lblPVThisTurn)
        Me.Controls.Add(Me.txtPVThisTurn)
        Me.Controls.Add(Me.txtDeploymentPV)
        Me.Controls.Add(Me.txtDeploymentzonename)
        Me.Controls.Add(Me.txtAvailablePoints)
        Me.Controls.Add(Me.lblDeploymentPV)
        Me.Controls.Add(Me.lblDeploy)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.lblFactionPV)
        Me.Controls.Add(Me.oobSelectUnit)
        Me.Name = "frmDeployment2"
        Me.Text = "frmDeployment2"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub New(ByVal depZone As DeploymentZone, ByRef game As CampaignerGameData)
        CurrentGame = game
        ptrDepZone = depZone

    End Sub

    Public ReadOnly Property CancelPressed() As Boolean
        Get
            Return bCancelled
        End Get
    End Property

    Public WriteOnly Property CurrentGame() As CampaignerGameData
        Set(ByVal Value As CampaignerGameData)
            'ptrcurrentGame = Value

            'unit.Name = "New Unit"
            'cruCreateUnit.CurrentGame = ptrcurrentGame
            'cbgBattlegroup.CurrentGame = ptrcurrentGame
            'cruCreateUnit.Unit = unit
            'oobSelectUnit.CurrentGame = ptrcurrentGame
            'txtAvailablePoints.Text = ptrcurrentGame.selectedFaction.FactionTotalPoints

        End Set
    End Property

    Public WriteOnly Property DepZone() As DeploymentZone
        Set(ByVal Value As DeploymentZone)
            'ptrDepZone = Value
            'txtDeploymentzonename.Text = ptrDepZone.ZoneName
            'If Not unit Is Nothing Then
            '    txtDeploymentPV.Text = ptrDepZone.MaxTotalDeploy.ToString - unit.InitialPointValue
            'Else
            '    txtDeploymentPV.Text = ptrDepZone.MaxTotalDeploy
            'End If

        End Set
    End Property

    Public ReadOnly Property DeployedUnit() As UnitType
        Get
            'Return unit
        End Get
    End Property

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If bPointValueInvalid Then
            MessageBox.Show("You have entered an invalid point value. You do not have enough points in the deployment zone or available to your faction to deploy this unit.", "Invalid Point Value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        If Valid() = False Then Exit Sub

        bCancelled = False

        Me.Hide()

    End Sub

    Private Function Valid() As Boolean
        'check to make sure required values are set, and posts a message if its not right
        'If bUsingOOB = True Then
        '    unit = oobSelectUnit.Unit
        '    ptrcurrentGame.selectedFaction.OrderOfBattle.Remove(unit)
        'End If

        'If (unit.Icon(IconImageIndex_cgd.Owner) Is Nothing) Or (unit.Icon(IconImageIndex_cgd.Enemy) Is Nothing) Or (unit.Icon(IconImageIndex_cgd.SameFaction) Is Nothing) Then
        '    MessageBox.Show("All icons must have an image.", "Icon Missing", MessageBoxButtons.OK)
        '    Return False
        'End If

        'If unit.Name = "" Then
        '    MessageBox.Show("You must name this unit.", "Name Missing", MessageBoxButtons.OK)
        '    Return False
        'End If

        'If Not TypeOf unit Is BattlegroupChit Then
        '    If unit.TypeName = "" Then
        '        MessageBox.Show("You must select a unit type before deploying.", "Select Unit Type", MessageBoxButtons.OK)
        '        Return False
        '    End If
        'End If

        Return True

    End Function

    Private Sub cruCreateUnit_PointValueChange(ByVal newval As Integer) Handles cruCreateUnit.PointValueChange, cbgBattlegroup.PointValueChanged, oobSelectUnit.PointValueChanged
        ' this is the amount available
        NewPointValue(newval)

    End Sub

    Private Sub NewPointValue(ByVal newValue As Integer)
        Dim available As Integer = ptrDepZone.MaxDeploymentPerTurn - ptrDepZone.PointsDeployedThisTurn - newValue
        txtPVThisTurn.Text = available

        bPointValueInvalid = False

        If available < 0 Then
            txtPVThisTurn.BackColor = Color.Salmon
            bPointValueInvalid = True
        Else
            txtPVThisTurn.BackColor = Color.WhiteSmoke
        End If

        available = ptrDepZone.MaxTotalDeploy - newValue
        txtDeploymentPV.Text = available

        If available < 0 Then
            txtDeploymentPV.BackColor = Color.Salmon
            bPointValueInvalid = True
        Else
            txtDeploymentPV.BackColor = Color.WhiteSmoke
        End If

        available = ptrcurrentGame.selectedFaction.FactionFreePoints - newValue
        txtAvailablePoints.Text = available

        If available < 0 Then
            txtAvailablePoints.BackColor = Color.Salmon
            bPointValueInvalid = True
        Else
            txtAvailablePoints.BackColor = Color.WhiteSmoke
        End If
    End Sub

    Private Sub btnCreateBG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateBG.Click
        unit = New BattlegroupChit
        'unit.GroundChitClass = GroundChitClass_cgd.Unit

        cruCreateUnit.Visible = False
        cbgBattlegroup.Visible = True
        oobSelectUnit.Visible = False
        cbgBattlegroup.Unit = unit

        btnCreateBG.BackColor = Color.DeepSkyBlue
        btnCreateUnit.BackColor = Color.LightBlue
        btnUseOOB.BackColor = Color.LightBlue
        bUsingOOB = False

    End Sub

    Private Sub btnCreateUnit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateUnit.Click
        'unit = New UnitType

        'cruCreateUnit.Visible = True
        'cbgBattlegroup.Visible = False
        'oobSelectUnit.Visible = False
        'cruCreateUnit.Unit = unit
        'btnCreateUnit.BackColor = Color.DeepSkyBlue
        'btnCreateBG.BackColor = Color.LightBlue
        'btnUseOOB.BackColor = Color.LightBlue
        'bUsingOOB = False

    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        bCancelled = True
        Me.Hide()
    End Sub

    Private Sub btnUseOOB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUseOOB.Click
        'unit = New UnitType

        ''// when selecting an oob unit, the unit is set in VALIDATE.

        'cruCreateUnit.Visible = False
        'cbgBattlegroup.Visible = False
        'oobSelectUnit.Visible = True
        'oobSelectUnit.CurrentGame = ptrcurrentGame
        'btnCreateUnit.BackColor = Color.LightBlue
        'btnCreateBG.BackColor = Color.LightBlue
        'btnUseOOB.BackColor = Color.DeepSkyBlue
        'bUsingOOB = True

    End Sub
End Class
